package com.lkd.controller;

import com.lkd.dto.PartnerDto;
import com.lkd.entity.Partner;
import com.lkd.service.IPartnerService;
import com.lkd.vo.PageBean;
import com.lkd.vo.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class PartnerController {

    private final IPartnerService partnerService;

    /**
     * 新增合作商
     * @param partner
     * @return
     */
    @PostMapping("/api/user-service/partner")
    public Result save(@RequestBody Partner partner) {
        partnerService.save(partner);
        return Result.success(true);
    }

    /**
     * 分页查询
     * @param partnerDto
     * @return
     */
    @GetMapping("/api/user-service/partner/search")
    public PageBean<Partner> search(PartnerDto partnerDto) {
        return partnerService.search(partnerDto);
    }

    @GetMapping("/api/user-service/partner/{id}")
    public Result findById(@PathVariable Long id) {
        Partner byId = partnerService.getById(id);
        return Result.success(byId);
    }

    @GetMapping("count")
    public Result count() {
        return Result.success(partnerService.count());
    }



}
